<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css">
		<style>
			.mui-content-padded{margin:5px 0 0 0;}
			.mui-row-list span{float: left; line-height:33px; width:20%;}
			.mui-row-list select{float: left; line-height:14px; font-size:14px; margin-top:2px; margin-left: 5px;}
			.mui-btn-block{margin-bottom:0; padding:6px;}
			.mui-col-sm-12{ border-top: 1px solid #D1D1D1; width:100%; padding-top:5px; font-size:14px;}
			input[type="text"],input[type="number"]{height:26px; padding: 0;border-width:0;margin-bottom:0;background:none;}
			form:before{ background: none !important; border: none !important;}
			input{border-width:0; text-align: right; font-size:14px; height: 26px;}
			.bottom_soild{border-bottom: 1px solid #DDDDDD; margin-right: 5px;}
			.submit{
				margin:0 auto 10px auto; 
				width:200px; 
				height:35px; 
				line-height: 35px; 
				background-color:#007AFF; 
				text-align: center; 
				color: #FFFFFF; 
				border-radius: 10px;
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">体征录入</h1>
		</header>
		<div class="mui-conten" style="margin-top:50px;">
			<div style="margin-left:0.9rem; line-height:35px;">血压</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">收缩压</div>
							<div style="float:right;">mmhg</div>
							<input id='mmhg' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
					</div>
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">舒张压</div>
							<div style="float:right;">mmhg</div>
							<input id='mmhg1' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
					</div>
				</div>
			</ul>
			<div style="margin-left:0.9rem; line-height:35px;">体重</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">目前体重</div>
							<div style="float:right;">Kg</div>
							<input id='kg' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">目标体重</div>
							<div style="float:right;">Kg</div>
							<input id='kg1' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
					</div>
				</div>
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">身高</div>
							<div style="float:right;">cm</div>
							<input id='cm' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
					</div>
				</div>
			</ul>
			<div style="margin-left:0.9rem; line-height:35px;">体质指数（BMI）</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">目前体质指数</div>
							<div style="float:right;">Kg/m²</div>
							<input id='bmi' class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">目标体质指数</div>
							<div style="float:right;">Kg/m²</div>
							<input id='bmi1' class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
					</div>
				</div>
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-col-sm-12 mui-col-xs-12">
					<li class="mui-table-view-cell">
						<a id='demo4' data-options='{"type":"date"}' class="btn mui-navigate-right">
							<div style="padding: inherit; float: left; font-size: 14px; width: 130px; line-height: 26px; margin: -11px -15px;">足背动脉搏动</div>
							<input id='footpul' class="ui-alert" placeholder="请选择" style="width:50%; text-align: right; float: right; padding-right: 15px; line-height: 26px;"/>
						</a>
					</li>
				</div>	
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">其他</div>
							<input id='other1' class="ui-alert bottom_soild" placeholder="请输入" style="width:80%; float: right;"/>
						</li>
					</div>
				</div>
			</ul>
			<div onclick="submit()" class="submit" >保存</div>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script src="../js/request.js"></script>
		<script type="text/javascript">
			//获取变量
			var self = localStorage.getItem("name")
			console.log(self)
			var dataold = JSON.parse(self)
			var obj = dataold.obj
			var selfdata ="";
			var listdata ="";
			mui.plusReady(function(){
				var self = plus.webview.currentWebview()
					listdata = self.data
					visitId = self.visitdata
					selfdata = JSON.parse(listdata)
					console.log(selfdata)
					console.log(selfdata.ehrId)
				var date1 = new Date();
				var year1=date1.getFullYear(); 
				var month1=date1.getMonth()+1;
				var day1=date1.getDate();
				var h1=date1.getHours();
				var m1=date1.getMinutes();
				var s1=date1.getSeconds();
					month1 =(month1<10 ? "0"+month1:month1); 
					day1 =(day1<10 ? "0"+day1:day1); 
					h1 =(h1<10 ? "0"+h1:h1); 
					m1 =(m1<10 ? "0"+m1:m1); 
					s1 =(s1<10 ? "0"+s1:s1);
					createDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					modifyDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					ehrId = selfdata.ehrId;
				if(self.second != ""){
					first = JSON.parse(self.first);
					second = JSON.parse(self.second);
					id = first.id;
					createUser = first.createUser;
					createDate = first.createDate;
					console.log(self.second);
					for(var i=0; i<second.length; i++){
						var kg_1;
						var kg1_1;
						var cm_1;
						var bmi_1;
						var bmi_2;
						if(second[i].questionId == "85"){
							document.getElementById("mmhg").value = second[i].answer;
						}
						if(second[i].questionId == "86"){
							document.getElementById("mmhg1").value = second[i].answer;
						}
						if(second[i].questionId == "89"){
							document.getElementById("kg").value = second[i].answer;
							document.getElementById("kg1").value = second[i].expectedAnswer;
							kg_1 = second[i].answer;
							kg1_1 = second[i].expectedAnswer;
						}
						if(second[i].questionId == "88"){
							document.getElementById("cm").value = second[i].answer;
							cm_1 = second[i].answer;
						}
						if(second[i].questionId == "136"){
							var rowsfootpul=resultall.r1
							for(var j=0; j<rowsfootpul.length; j++){
								if(second[i].answer == rowsfootpul[j].id){
								console.log("123")
									document.getElementById("footpul").value = rowsfootpul[j].value + rowsfootpul[j].text;
								}
							}
						}
						if(second[i].questionId == "335"){
							document.getElementById("other1").value = second[i].answer;
						}
						bmi.value = parseFloat(kg_1/cm_1/cm_1*10000).toFixed(2);
						bmi1.value = parseFloat(kg1_1/cm_1/cm_1*10000).toFixed(2);
					}
				}
			})
			//赋值
			var resultall = {"r1":[{value:' ',id:'0',text:' '},
									{value:'触及正常',id:'164_0',text:' '},
									{value:'减弱',id:"610_0",text:" , 双侧"},
									{value:'减弱',id:"610_1",text:" , 左侧"},
									{value:'减弱',id:"610_2",text:" , 右侧"},
									{value:'消失',id:"611_0",text:" , 双侧"},
									{value:'消失',id:"611_1",text:" , 左侧"},
									{value:'消失',id:"611_2",text:" , 右侧"}]}
			var id = 0;
			var visitId= 0;
			var ehrId = "";
			var manageId = 0;
			var createUser = obj.id;
			var createDate = "";
			var modifyUser = obj.id;
			var modifyDate = "";
			var statelr = "";
			mui.init()
			(function($) {
				$.init();
				var result = $('#result')[0];
				var btns = $('.btn');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var _self = this;
						if(_self.picker) {
							_self.picker.show(function (rs) {
								result.innerText = rs.text;
								_self.picker.dispose();
								_self.picker = null;
							});
						} else {
							if(i == 0){
								var picker = new mui.PopPicker({
									layer:2
								});
									picker.setData([{//前端数据结构
										value: '0',id: '164',text: '触及正常',
										children: [{value: "164_0",text: " "}]
									},{//前端数据结构
										value: '1',id: '610',text: '减弱',
										children: [{value: "610_0",text: " , 双侧"},
												{value: "610_1",text: " , 左侧"},
												{value: "610_2",text: " , 右侧"}]
									},{//前端数据结构
										value: '2',id: '611',text: '消失',
										children:[{value: "611_0",text: " , 双侧"},
												{value: "611_1",text: " , 左侧"},
												{value: "611_2",text: " , 右侧"}]
									}])
								picker.pickers[0].setSelectedIndex(1);
								picker.pickers[1].setSelectedIndex(1);
								picker.show(function(SelectedItem) {
									$('#footpul')[0].value = SelectedItem[0].text+SelectedItem[1].text;//前台显示
									statelr = SelectedItem[1].value;
								})
							} else{
								
							}
						}
					}, false);
				});
			})(mui);
			//计算BMI
			var kg = document.getElementById("kg");
			var kg1 = document.getElementById("kg1");
			var m = document.getElementById("cm");
			var bmi = document.getElementById("bmi");
			var bmi1 = document.getElementById("bmi1");
			kg.addEventListener('input',function(){
				bmi.value = parseFloat(kg.value/m.value/m.value*10000).toFixed(2);
			});
			kg1.addEventListener('input',function(){
				bmi1.value = parseFloat(kg1.value/m.value/m.value*10000).toFixed(2);
			});
			m.addEventListener('input',function(){
				bmi.value = parseFloat(kg.value/m.value/m.value*10000).toFixed(2);
				bmi1.value = parseFloat(kg1.value/m.value/m.value*10000).toFixed(2);
			});
			//提交
			function submit(){
				var statelr_1 = $('#footpul')[0].value;
				for(var re=0; re<resultall.r1.length; re++){
					var statelr_2 = resultall.r1[re].value+resultall.r1[re].text;
					if(statelr_1 == statelr_2){
						statelr = resultall.r1[re].id;
					}
				}
				var dataobj=[
					//收缩压
					{'id':id,
					'ehrId':ehrId,
					"manageId":manageId,
					"visitId":visitId,
					"questionId":"85",
					"answerId":"0",
					"answer":mui("#mmhg")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUser":createUser,
					"modifyUser":modifyUser},
					//舒张压
					{'id':id,
					'ehrId':ehrId,
					"manageId":manageId,
					"visitId":visitId,
					"questionId":"86",
					"answerId":"0",
					"answer":mui("#mmhg1")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUser":createUser,
					"modifyUser":modifyUser},
					//体重
					{'id':id,
					'ehrId':ehrId,
					"manageId":manageId,
					"visitId":visitId,
					"questionId":"89",
					"answerId":"0",
					"answer":mui("#kg")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":mui("#kg1")[0].value,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUser":createUser,
					"modifyUser":modifyUser},
					//身高
					{'id':id,
					'ehrId':ehrId,
					"manageId":manageId,
					"visitId":visitId,
					"questionId":"88",
					"answerId":"0",
					"answer":mui("#cm")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUser":createUser,
					"modifyUser":modifyUser},
					//足背动脉搏动
					{'id':id,
					'ehrId':ehrId,
					"manageId":manageId,
					"visitId":visitId,
					"questionId":"136",
					"answerId":"0",
					"answer":statelr,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUser":createUser,
					"modifyUser":modifyUser},
					//其它
					{'id':id,
					'ehrId':ehrId,
					"manageId":manageId,
					"visitId":visitId,
					"questionId":"335",
					"answerId":"0",
					"answer":mui("#other1")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUser":createUser,
					"modifyUser":modifyUser}
				]
				$.ajax({
					type: 'post',
					url:getRequestUrl.url+"/mobile/ehr/DiabetesPersonAnswer/addOrUpdate",
					data:JSON.stringify(dataobj),
					dataType:"json",
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.status==1){
							alert("提交成功")
							mui.openWindow({
								url: 'follow_up_add.html', 
								id:'follow_up_add',
								extras:{
									
								}
							});
						}else{
							alert(data.message);
						}
					},
					error:function(xhr,type,errorThrown){
						
					}
				})
			}
		</script>
	</body>

</html>